const path = require("path");
const webpack = require("webpack");

const execSync = require('child_process').execSync; //同步子进程
const fs = require('fs'); //文件读取模块

let name = execSync('git show -s --format=%ce').toString().trim(); //姓名
let date = new Date(); //日期

let bannerInfo=`Build By：${name}\nDate：${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
console.log(bannerInfo.toString());

function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  lintOnSave: false,
  devServer:{
    // host:'127.0.0.1'
    // host:'127.0.0.1'
  },
  configureWebpack: {
    plugins: [
      new webpack.BannerPlugin(
          {
            banner: bannerInfo, // 其值为字符串，将作为注释存在
          }
      )

    ]
  },
  chainWebpack(config) {

    // set svg-sprite-loader
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();

  }

};
